﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entidades.Espectaculos;
using System.Data.SqlClient;
using System.Configuration;

namespace Datos.Espectaculos
{
    public class EspRepresentanteDAL
    {
        public static List<EspRepresentante> ListarRepresentante(int estado)
        {
            string cnx = ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString();
            SqlConnection con = new SqlConnection(cnx);
            SqlCommand com = new SqlCommand("[dbo].[sp_Esp_ListarRepresentante]", con);
            com.Parameters.AddWithValue("@Estado", estado);

            com.CommandType = System.Data.CommandType.StoredProcedure;
            try
            {
                con.Open();
                SqlDataReader dr = com.ExecuteReader();
                List<EspRepresentante> lista = new List<EspRepresentante>();
                EspRepresentante obj = null;
                while (dr.Read())
                {
                    obj = new EspRepresentante();
                    obj.IdRepresentante = Convert.ToInt32(dr["IdRepresentante"].ToString());
                    obj.RazonSocial = dr["RazonSocial"].ToString();
                    obj.Correo = dr["Correo"].ToString();
                    obj.Direccion = dr["Direccion"].ToString();
                    obj.Telefono = dr["Telefono"].ToString();
                    obj.RUC = dr["RUC"].ToString();
                    obj.Observacion = dr["Observaciones"].ToString();
                    obj.Estado = Convert.ToInt32(dr["Estado"].ToString());

                    lista.Add(obj);
                }
                dr.Close();

                return lista;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();

            }

        }
    }
}
